using System;
using System.Text.RegularExpressions;
namespace BMC.ARSystem
{
	internal class ARXCharWriter : ARXDataTypeWriter
	{
		internal ARXCharWriter()
		{
		}
		public static string EscapeString(string val)
		{
			Regex regex = new Regex("\\\\|\r\n|\r|\n");
			return Util.QuoteStringForARX(regex.Replace(val, new MatchEvaluator(ARXCharWriter.EscapeMatch)));
		}
		private static string EscapeMatch(Match match)
		{
			if (match.get_Value() == "\\")
			{
				return "\\\\";
			}
			if (match.get_Value() == "\r\n")
			{
				return "\\r\\n";
			}
			if (match.get_Value() == "\n")
			{
				return "\\r\\n";
			}
			if (match.get_Value() == "\r")
			{
				return "\\r\\n";
			}
			return match.get_Value();
		}
		internal override string WriteValue(object obj)
		{
			return ARXCharWriter.EscapeString(obj.ToString());
		}
	}
}
